package com.javacodegeeks.android.googlemaps;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
/****************************************************
 * Class  used marker to point on the map
 * @author ThangLQ
 *
 ****************************************************/
public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {
	/**
	 * Storage objects of OverlayItem
	 */
	private ArrayList<OverlayItem> mMapOverlays = new ArrayList<OverlayItem>();
	/**
	 * Context 
	 */
	private Context mContext;
	/**
	 * Select a point in googlemap
	 */
	private MapLocation mSelectMapLocation;
	/*************************************************
	 * Constructor
	 * @param defaultMarker Drawable for marker
	 *************************************************/
	public CustomItemizedOverlay(Drawable mDefaultMarker) {
		  super(boundCenterBottom(mDefaultMarker));
	}
	/**************************************************
	 * Constructor
	 * @param mDefaultMarker Drawable for marker
	 * @param mContext Context 
	 **************************************************/
	public CustomItemizedOverlay(Drawable mDefaultMarker, Context mContext) {
		  this(mDefaultMarker);
		  this.mContext = mContext;
	}

	/**************************************************
	 * Create object overlayItem at index i
	 **************************************************/
	@Override
	protected OverlayItem createItem(int i) {
		return mMapOverlays.get(i);
	}
	/**************************************************
	 * Return size of arraylist 
	 **************************************************/
	@Override
	public int size() {
		return mMapOverlays.size();
	}
	/**************************************************
	 * Tap screen map
	 **************************************************/
	@Override
	public boolean onTap(GeoPoint p, MapView mapView) {
		// TODO Auto-generated method stub
		return super.onTap(p, mapView);
	}
	/**************************************************
	 * 
	 **************************************************/
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		// TODO Auto-generated method stub
		super.draw(canvas, mapView, shadow);
	}
	/*	@Override
	protected boolean onTap(int mIndex) {
		OverlayItem item = mMapOverlays.get(mIndex);
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
	}
	*/
	/***************************************************
	 * Add new OverlayItem
	 * @param mOverlay
	 ***************************************************/
	public void addOverlay(OverlayItem mOverlay) {
		mMapOverlays.add(mOverlay);
	    this.populate();
	}

}
